package imsdk

import (
	"encoding/json"
	"longmen/server/config/global"
	"longmen/server/pkg/common/helper/http"
)

type (
	DestroyGroupRequest struct {
		GroupID string `json:"GroupId"`
	}
	DestroyGroupResponse struct {
		ActionStatus string `json:"ActionStatus"`
		ErrorInfo    string `json:"ErrorInfo"`
		ErrorCode    int    `json:"ErrorCode"`
	}
)

// DestroyGroup 解散群
func (s sdk) DestroyGroup(fansGroupId string) error {
	reqUrl := s.BuildRestfulUrl("/group_open_http_svc/destroy_group")
	req := DestroyGroupRequest{
		GroupID: fansGroupId,
	}
	bytes, err := json.Marshal(req)
	if err != nil {
		global.Log.Error("create group error: ", err)
		return err
	}

	result, err := http.HttpPost(reqUrl, string(bytes), connTimeoutMs, serveTimeoutMs, "application/json")
	if err != nil {
		global.Log.Error("create group error: ", err)
		return err
	}
	resp := CreteGroupResponse{}
	err = json.Unmarshal(result, &resp)
	if err != nil {
		global.Log.Error("create group Unmarshal error: ", err)
		return err
	}
	return nil
}
